package com.newshub.app.ui.video

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.newshub.app.data.model.VideoNews
import com.newshub.app.data.repository.NewsRepository
import kotlinx.coroutines.launch

class VideoViewModel : ViewModel() {
    
    private val repository = NewsRepository

    private val _videoNews = MutableLiveData<List<VideoNews>>()
    val videoNews: LiveData<List<VideoNews>> = _videoNews
    
    private val _isLoading = MutableLiveData<Boolean>()
    val isLoading: LiveData<Boolean> = _isLoading
    
    private val _errorMessage = MutableLiveData<String?>(null)
    val errorMessage: LiveData<String?> = _errorMessage
    
    fun loadVideoNews() {
        viewModelScope.launch {
            _isLoading.value = true
            _errorMessage.value = null
            try {
                // 直接使用Repository的模拟数据
                val videoList = repository.createMockVideoNewsList()
                _videoNews.value = videoList
            } catch (e: Exception) {
                _errorMessage.value = "加载视频失败: ${e.message}"
                _videoNews.value = emptyList()
            } finally {
                _isLoading.value = false
            }
        }
    }
}